from django.db import models
from utils.models import ModelBase


class InitialLogInfo(ModelBase):
    one_line = models.TextField(verbose_name='一条日志数据')

    class Meta:
        db_table = 'logAdmin_initial_log_info'
        verbose_name = '初始的日志信息（未清洗的）'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']


class LogInfo(ModelBase):
    ip = models.CharField(max_length=30, default='171.88.100.129', verbose_name='访问ip')
    visit_time = models.CharField(max_length=100, verbose_name='访问时间', default='06/Jan/2020:11:55:4')
    request_method = models.CharField(max_length=30, default='GET', verbose_name='请求方法')
    source_url = models.URLField(max_length=300, verbose_name='访问的资源url', default='/')
    protocol = models.CharField(max_length=30, verbose_name='协议', default='HTTP/1.1')
    status = models.IntegerField(default=200, verbose_name='访问状态码')

    body_size = models.IntegerField(verbose_name='请求包字节大小', default=0)
    http_refer = models.URLField(default='/', verbose_name='http代理（从站点内哪访问的）')
    user_agent = models.TextField(default='-', verbose_name='UserAgent')

    class Meta:
        db_table = 'logAdmin_log_info'
        verbose_name = '日志信息'
        verbose_name_plural = verbose_name

        ordering = ['-create_time']
